package paper.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import keter.domain.base.BaseEntity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * <p>Class       : paper.domain.Subject
 * <p>Descdription: 论文课题
 * @author  顾力行-gulx@neusoft.com
 * @version 1.0.0
 */
@MappedSuperclass
public class BasePaper extends BaseEntity implements Cloneable{
    //名称
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name){
        this.name = decode(name);
        //可以防XSS,但弊端是数据库中存入转义后字符，且在页面编辑时可能会显示“&lt;”
        //this.name = decodeEscapeHtml(this.name);
    }
    
    //内容0
    private String content;
    //@Column(columnDefinition = "longtext") 
    //columnDefinition="text", hsqldb不支持"text",或者是干脆不支持columnDefinition
    @Lob
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = decode(content);
    }
    
    //负责人
    private User master;
    @JsonIgnore
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="master_id")//关联主键
    public User getMaster() {
        return master;
    }
    public void setMaster(User master) {
        this.master = master;
    }
    @Transient
    public String getMasterName() {
        return master!=null?master.getName():"";
    }
    
    //状态
    private String status = AuditStatus.EDIT.toString();
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    private Date submitted;
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+08:00")
    public Date getSubmitted() {
        return submitted;
    }
    
    public void setSubmitted(Date submitted) {
        this.submitted = submitted;
    }
}
